package com.niodata.dp.expression.function.string;

import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.function.FunctionUtils;
import com.googlecode.aviator.runtime.type.AviatorObject;
import java.util.Map;

public class StringMatchFunction extends AbstractFunction {

  @Override
  public String getName() {
    return "string.match";
  }

  @Override
  public AviatorObject call(Map<String, Object> env, AviatorObject str, AviatorObject regex) {
    String src = (String) str.getValue(env);
    String pattern = (String) regex.getValue(env);
    boolean matched = src.matches(pattern);
    return FunctionUtils.wrapReturn(matched);
  }
}
